<html>
<head>
    <script type="text/javascript" language="javascript">
        function validasi() {
            var answer = document.getElementById("answer").value;
            var que = document.getElementById("quewrite").value;
            var img = document.getElementById("picture").value;
            var target = document.getElementsByName("option");

            if (answer == "" || answer == null) {
                err.innerHTML = "Please insert the answer!";
                return false;

            }
            else if (que == "" || que == null) {
                err.innerHTML = "Please insert the question!";
                return false;
            }
            else if (img == "" || img == null) {
                err.innerHTML = "Please insert the picture's name!";
                return false;
            }
            else if (img.indexOf(" ") >= 1) {
                err.innerHTML = "Picture's name can't contain spaces!";
                return false;
            }
            else if(target[0].checked == false && target[1].checked == false)
            {
                err.innerHTML = "Please choose the answer of the target word!";
                return false;
            }
            else {
                return true;
            }

        }
    </script>
</head>
<body>
<form action="saveWriting.jsp" method="post" onsubmit="return validasi()">
    <table id="word1">
        <%
            String tipe = request.getParameter("tipe");
            String category = request.getParameter("category");
            String idTest = request.getParameter("idTest");
            String namaTest = request.getParameter("namaTest");


            stat.executeQuery("Select * from categories where categoryID = '" + category + "' ");

            String catname = rs.getString("categoryName");

            String gabung = namaTest + "_";

            String gabunglagi = gabung + catname;

            stat.executeQuery("Select * from DetailTest where categoryID = '" + category + "' and testID = '" + idTest + "' ");
            if (rs.next() == false) {
                stat.executeUpdate("INSERT INTO DetailTest (categoryID, testID, detailName) values ('" + category + "', '" + idTest + "','" + gabunglagi + "') ");

            }

        %>

        <tr>
            <td>Question's Type</td>
            <td>:</td>
            <td><%=tipe%>
            </td>

        </tr>
        <tr>
            <td>Question's name</td>
            <td>:</td>
            <%
                stat.executeQuery("select * from DetailTest where categoryID = '" + category + "' and testID = '" + idTest + "' ");
                while (rs.next()) {
            %>
            <td><%out.print(rs.getString("detailName"));%></td>
            <td><input type="hidden" name="detailtestID" id="detailtestID"
                       value="<%out.print(rs.getString("detailtestID"));%>"></td>

            <%}%>
        </tr>
        <td><input type="hidden" name="idTest" id="idTest" value="<%out.print(idTest);%>"></td>
        <tr>
            <td>Question</td>
            <td>:</td>
            <td><input style="width: 400px" type="text" name="quewrite" id="quewrite"></td>

        </tr>
        <tr>
            <td>Answer</td>
            <td>:</td>
            <td><input style="width: 400px" type="text" name="answer" id="answer"></td>
        </tr>
        <tr>
            <td>Picture's Name</td>
            <td>:</td>
            <td style="color: red; font-weight: 600"><input type="text" style="width: 400px" name="picture"
                                                            id="picture"></td>
        </tr>
        <tr>
            <td colspan="3" style="color: red; padding-left: 110px; font-weight: 800">*Please make sure the picture is on the directory
            </td>
        </tr>
        <table>
            <tr>
                <td>Target Word</td>
                <td>:</td>
                <td>
                    <input type="radio" name="option" id="yes" value="yes"><label>Yes</label>
                    <input type="radio" name="option" id="no" value="no"><label>No</label>
                </td>


            </tr>
        </table>
        <tr id="warning">
            <td colspan="3">
                <div id="err"></div>
            </td>
        </tr>
        <tr align="right">
            <td colspan="3">
                <div class="btn-fld">
                    <button type="reset">Reset</button>
                    <button type="submit">Save</button>
                </div>

            </td>
        </tr>

    </table>
</form>
</body>
</html>